package com.djakapm.markdown.editor.component;

import com.djakapm.swing.component.SplitPaneView;
import com.djakapm.swing.component.tab.Tab;
import com.djakapm.swing.container.BorderPanel;

public class EditorComponentView extends BorderPanel {
    private MarkdownTextEditor markdownTextEditor;
    private MarkupView markupView;
    private Tab contentTabPane;
    private int index;

    public void showSaveDialog(){
        this.markdownTextEditor.getFileDialog().showSaveDialog(null);
    }

    public boolean hasSelectedFile(){
        return this.markdownTextEditor.getFileDialog().getSelectedFile() != null;
    }

    public String getSelectedFilePath(){
        return this.markdownTextEditor.getFileDialog().getSelectedFile().getPath();
    }


    public void setMarkupContent(String content){
        this.markupView.setText(content);
    }

    public String getMarkdownContent(){
        return this.markdownTextEditor.getText();          
    }

    public void setIndex(int index) {
        this.index = index;
    }

    public EditorComponentView setTitle(String title){
        this.contentTabPane.setTitleAt(this.index,title);
        return this;
    }

    public EditorComponentView(Tab contentTabPane){
        this.contentTabPane = contentTabPane;
    }
    

    public void init(){
        this.markupView = new MarkupView();
        this.markdownTextEditor = new MarkdownTextEditor();
        SplitPaneView splitPane = new SplitPaneView();
        splitPane.splitHorizontally(this.getMarkdownTextEditor(), this.getMarkupView());
        splitPane.setOneTouchExpandable(true);
        this.addToCenter(splitPane);
    }


    public MarkdownTextEditor getMarkdownTextEditor() {
        return markdownTextEditor;
    }

    public MarkupView getMarkupView() {
        return markupView;
    }
}
